/// 首页附近商家请求模型
class HomeNearbyRequest {
  final double latitude;     // 纬度
  final double longitude;    // 经度
  final int? shopLimit;      // 商铺显示数量，默认10
  final int? page;           // 页码，默认1
  final int? userId;         // 用户ID（用于检查点赞状态）
  final List<String>? category; // 分类筛选
  final String timestamp;    // 时间戳（用于加密）

  HomeNearbyRequest({
    required this.latitude,
    required this.longitude,
    this.shopLimit,
    this.page,
    this.userId,
    this.category,
    required this.timestamp,
  });

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {
      'latitude': latitude,
      'longitude': longitude,
      'timestamp': timestamp,
    };
    
    if (shopLimit != null) data['shop_limit'] = shopLimit;
    if (page != null) data['page'] = page;
    if (userId != null) data['userId'] = userId;
    if (category != null && category!.isNotEmpty) data['Category'] = category;
    
    return data;
  }

  factory HomeNearbyRequest.fromJson(Map<String, dynamic> json) {
    return HomeNearbyRequest(
      latitude: (json['latitude'] as num).toDouble(),
      longitude: (json['longitude'] as num).toDouble(),
      shopLimit: json['shop_limit'] as int?,
      page: json['page'] as int?,
      userId: json['userId'] as int?,
      category: json['Category'] != null ? List<String>.from(json['Category']) : null,
      timestamp: json['timestamp'] as String,
    );
  }

  @override
  String toString() {
    return 'HomeNearbyRequest(latitude: $latitude, longitude: $longitude, shopLimit: $shopLimit, page: $page, userId: $userId, category: $category, timestamp: $timestamp)';
  }
}
